#!/usr/bin/env python
# -*- coding: utf-8 -*-
#本代码来自所出售产品的淘宝店店主编写
#未经受权不得复制转发
#淘宝店：https://fengmm521.taobao.com/
#再次感谢你购买本店产品
import os 
import time
import cv2
import httpUtil
from magetool import pathtool


def ocr(spth = None):
    if not spth:
        spth = os.getcwd() + os.sep + 'test.jpg'
    print(spth)
    imImg = cv2.imread(spth)
    starttime = time.time()
    dat = httpUtil.httpPostImg(imImg,ip = '127.0.0.1',port = 8889)    #ocr测试
    endtime = time.time()
    # print(dat)
    for i,v in enumerate(dat[0]):
        print(i,v)
    dittime = endtime - starttime
    print('stime:%.3f,etime:%.3f,dtime:%.3f'%(starttime,endtime,dittime))
def test():
    # for i in range(1000):
    #     time.sleep(3)
    #     ocr()
    fs = pathtool.getAllExtFile(pathtool.cur_file_dir() + os.sep + 'imgout','.jpg')
    print(fs)
    for i,v in enumerate(fs):
        fname = v[2]
        fpth = pathtool.cur_file_dir() + os.sep + 'imgout' +os.sep + fname + '.jpg'
        ocr(fpth)
        time.sleep(3)

def main():

    spth = os.getcwd() + os.sep + '1.jpg'
    print(spth)
    imImg = cv2.imread(spth)
    starttime = time.time()
    dat = httpUtil.httpPostImg(imImg,ip = '127.0.0.1',port = 8889)    #ocr测试
    endtime = time.time()
    # print(dat)
    for i,v in enumerate(dat[0]):
        print(i,v)
    dittime = endtime - starttime
    print('stime:%.3f,etime:%.3f,dtime:%.3f'%(starttime,endtime,dittime))
    time.sleep(3)
if __name__ == '__main__':
    # main()
    test()
